#pragma once

#include <string>
#include <unordered_map>
#include "classpath/class_path.hpp"

namespace jvm {
namespace heap {

class Class;
// class ClassPath;

class ClassLoader {
private:
    std::shared_ptr<classpath::ClassPath> m_pClasspath;
    std::unordered_map<std::string, std::shared_ptr<Class>> m_classMap;

public:
    ClassLoader(std::shared_ptr<classpath::ClassPath> pClasspath);
    std::shared_ptr<Class> loadClass(const std::string& name);

private:
    std::shared_ptr<Class> loadNonArrayClass(const std::string& name);
    std::pair<std::vector<uint8_t>, classpath::Entry> readClass(const std::string& name);
    std::shared_ptr<Class> defineClass(const std::vector<uint8_t>& data);
    static void link(std::shared_ptr<Class> pClass);
};

} // namespace heap
} // namespace jvm
